package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.BusinessProductEntity;
import com.xbongbong.saas.domain.entity.WorkOrderProductEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 *
 * @author 刘阳
 * @date 2019/4/23 4:03 PM
 * @since v1.0
 * @version v1.0
 */
@Repository
@Mapper
public interface WorkOrderProductDao {
    Integer insert(WorkOrderProductEntity workOrderProduct);

    /**
     * 批量插入
     * @param productAddList
     * @return
     */
    Integer insertBatch(@Param("list") List<WorkOrderProductEntity> productAddList);

    Integer update(WorkOrderProductEntity workOrderProduct);

    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);

    WorkOrderProductEntity getByKey (@Param("key") Long key,@Param("corpid") String corpid);

    List<WorkOrderProductEntity> findEntitys(@Param("param") Map<String, Object> param);

    Integer getEntitysCount(@Param("param")Map<String ,Object>  param);

    /**
     * Description: 批量删除
     * @param workOrderIdIn
     * @param corpid
     * @return java.lang.Integer
     * @author 魏荣杰
     * @date 2019/5/9 11:07
     * @since v1.0
     */
    Integer deleteByWorkOrderIdIn(@Param("list") List<Long> workOrderIdIn, @Param("corpid") String corpid);

    List<BusinessProductEntity> findProductNum(@Param("param") Map<String,Object> param);

    /**
     * 批量删除
     * @param idIn 产品id列表
     * @param corpid 公司id
     * @return 删除行数
     */
    Integer deleteByIdIn(@Param("corpid") String corpid, @Param("idIn") List<Long> idIn, @Param("del") Integer del);

    Integer updateBatch(@Param("list") List<WorkOrderProductEntity> list,@Param("corpid") String corpid);

    Integer updateOutstockBatch(@Param("list") List<WorkOrderProductEntity> list,@Param("corpid") String corpid);

    Integer findProductNumCount(@Param("param") Map<String, Object> param);

    List<BusinessProductEntity> findProductNumIncludeProcess(@Param("param") Map<String,Object> param);

    Integer findProductNumCountIncludeProcess(@Param("param") Map<String,Object> param);

    Long isProductSubAttrExist(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("isArray") Integer isArray);


    Double summaryByAttr( @Param("field") String field,@Param("corpid") String corpid, @Param("refId") Long refId, @Param("productIdIn") List<Long> productIdIn);

    List<String> getCorpidList();


    Double summaryByAttrFromOutSide( @Param("field") String field,@Param("corpid") String corpid, @Param("refId") Long refId, @Param("productIdIn") List<Long> productIdIn);

    Double calcuateByAttrFromOutSide(@Param("field1")String field1,@Param("field2") String field2,@Param("corpid") String corpid,@Param("refId") Long refId,@Param("productIdIn") List<Long> productIdIn);

    Long countProductSub(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("isArray") Integer isArray);

    List<WorkOrderProductEntity> getProductWithSubData(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("isArray") Integer isArray, @Param("idGte") Long idGte, @Param("limit") Integer limit);

    Integer updateMulti(@Param("list") List<WorkOrderProductEntity> list,  @Param("corpid") String corpid);

}
